import java.util.Arrays;

public class NonoverlappingIntervals0108_435 {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals,(o1,o2)-> o1[1] - o2[1]); //按照右边界排序。

        int res = 0;
        for (int i = 1; i < intervals.length; i++) {
            if(intervals[i][0] < intervals[i-1][1]){
                intervals[i][1] = Math.min(intervals[i][1], intervals[i-1][1]);
                res++;
            }
        }
        return res;
    }
}
